this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.Ui=this.BX.Landing.Ui||{};this.BX.Landing.Ui.Panel=this.BX.Landing.Ui.Panel||{};this.BX.Landing.Ui.Panel.Formsettingspanel=this.BX.Landing.Ui.Panel.Formsettingspanel||{};(function(e,t,i,n,a,r,s,o,l,c,d,g){"use strict";var u;var m=function e(t){return!d.Type.isNil(t.ID)?t.ID:t.id};var h=function e(t){return!d.Type.isNil(t.NAME)?t.NAME:t.name};var p=function(e){babelHelpers.inherits(t,e);function t(e){var i;babelHelpers.classCallCheck(this,t);i=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));d.Dom.replace(i.input,i.getInner());return i}babelHelpers.createClass(t,[{key:"getInner",value:function e(){var t=this;return this.cache.remember("inner",(function(){return d.Tag.render(u||(u=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-field-stages">\n\t\t\t\t\t',"\n\t\t\t\t</div>\n\t\t\t"])),t.getCategoriesDropdown().getLayout())}))}},{key:"getCategoriesDropdown",value:function e(){var t=this;return this.cache.remember("categoriesDropdown",(function(){return new BX.Landing.UI.Field.Dropdown({title:t.options.listTitle||c.Loc.getMessage("LANDING_FORM_SETTINGS_CATEGORIES_FIELD_TITLE"),content:t.options.value.category,items:t.options.categories.map((function(e){return{name:h(e),value:m(e)}})),onChange:t.onCategoryChange.bind(t)})}))}},{key:"getCurrentCategory",value:function e(){var t=this.getCategoriesDropdown().getValue();return this.options.categories.find((function(e){return String(m(e))===String(t)}))}},{key:"onCategoryChange",value:function e(){this.emit("onChange")}},{key:"getValue",value:function e(){return{category:this.getCategoriesDropdown().getValue(),stage:""}}},{key:"setValue",value:function e(t){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;this.getCategoriesDropdown().setValue(t.category);if(!i){this.emit("onChange")}}}]);return t}(l.BaseField);function y(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function f(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?y(Object(i),!0).forEach((function(t){babelHelpers.defineProperty(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):y(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function _(e,t,i){S(e,t);t.set(e,i)}function S(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}var E=new WeakMap;var T=function(e){babelHelpers.inherits(n,e);function n(e){var t;babelHelpers.classCallCheck(this,n);t=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(n).call(this,e));_(babelHelpers.assertThisInitialized(t),E,{writable:true,value:void 0});t.setEventNamespace("BX.Landing.UI.Panel.FormSettingsPanel.CrmContent");babelHelpers.classPrivateFieldSet(babelHelpers.assertThisInitialized(t),E,new g.SchemeManager(babelHelpers.toConsumableArray(e.dictionary.document.schemes)));t.addItem(t.getHeader());t.addItem(t.getTypesField());if(t.isDynamicAvailable()){t.addItem(t.getDynamicEntitySettingsForm())}t.addItem(t.getExpertSettingsForm());t.addItem(t.getOrderSettingsForm());t.setLastScheme(t.options.formOptions.document.scheme);t.setLastDealCategory(t.options.formOptions.document.deal.category);return t}babelHelpers.createClass(n,[{key:"isDynamicAvailable",value:function e(){return d.Type.isArrayFilled(this.options.dictionary.document.dynamic)}},{key:"getHeader",value:function e(){return this.cache.remember("header",(function(){return new i.HeaderCard({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TITLE")})}))}},{key:"getDuplicatesField",value:function e(){var t=this;return this.cache.remember("duplicatesField",(function(){return new BX.Landing.UI.Field.Radio({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_DUPLICATES_FIELD_TITLE"),selector:"duplicateMode",value:[t.options.formOptions.document.duplicateMode?t.options.formOptions.document.duplicateMode:"ALLOW"],items:[{name:c.Loc.getMessage("LANDING_FORM_SETTINGS_DUPLICATES_ALLOW"),value:"ALLOW"},{name:c.Loc.getMessage("LANDING_FORM_SETTINGS_DUPLICATES_REPLACE"),value:"REPLACE"},{name:c.Loc.getMessage("LANDING_FORM_SETTINGS_DUPLICATES_MERGE"),value:"MERGE"}]})}))}},{key:"getOrderSettingsForm",value:function e(){var t=this;return this.cache.remember("formSettingsForm",(function(){var e=t.getSchemeById(t.options.formOptions.document.scheme);var i=function(){if(e&&e.dynamic===true){return String(e.id).endsWith("1")}return d.Text.toNumber(t.options.formOptions.document.scheme)>4}();return new s.FormSettingsForm({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_ORDER_HEADER"),toggleable:true,opened:i,fields:[]})}))}},{key:"getType1Header",value:function e(){return this.cache.remember("type1header",(function(){return new i.HeaderCard({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_1").replace("&nbsp;"," "),level:2})}))}},{key:"getType2Header",value:function e(){return this.cache.remember("type2header",(function(){return new i.HeaderCard({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_2").replace("&nbsp;"," "),level:2})}))}},{key:"getType3Header",value:function e(){return this.cache.remember("type3header",(function(){return new i.HeaderCard({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_3").replace("&nbsp;"," "),level:2})}))}},{key:"getType4Header",value:function e(){return this.cache.remember("type4header",(function(){return new i.HeaderCard({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_4").replace("&nbsp;"," "),level:2})}))}},{key:"getType6Header",value:function e(){return this.cache.remember("type6header",(function(){return new i.HeaderCard({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_6").replace("&nbsp;"," "),level:2})}))}},{key:"getDynamicHeader",value:function e(t){var n=this.cache.remember("dynamicHeader",(function(){return new i.HeaderCard({title:"",level:2})}));if(d.Type.isString(t)){n.setTitle(t)}return n}},{key:"getDynamicEntitiesField",value:function e(){var t=this;return this.cache.remember("dynamicEntitiesField",(function(){var e=t.getSchemeById(t.options.formOptions.document.scheme);return new BX.Landing.UI.Field.Dropdown({selector:"dynamicScheme",title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_SMART_ENTITY_LIST"),items:t.options.dictionary.document.dynamic.map((function(e){return{name:e.name,value:e.id}})),content:e.mainEntity,onChange:function e(){t.onTypeChange(new r.BaseEvent({data:{item:{id:t.getSelectedSchemeId()}}}))}})}))}},{key:"getDynamicEntitySettingsForm",value:function e(){var t=this;return this.cache.remember("dynamicEntitySettingsForm",(function(){return new s.FormSettingsForm({opened:true,hidden:true,fields:[t.getDynamicEntitiesField()]})}))}},{key:"getExpertSettingsForm",value:function e(){var t=this;return this.cache.remember("expertSettingsForm",(function(){return new s.FormSettingsForm({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_EXPERT_MODE"),toggleable:true,toggleableType:s.FormSettingsForm.ToggleableType.Link,opened:false,fields:[new i.HeaderCard({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_1").replace("&nbsp;"," "),level:2}),t.getDuplicatesField()]})}))}},{key:"getTypesField",value:function e(){var t=this;return this.cache.remember("typesField",(function(){setTimeout((function(){t.onTypeChange(new r.BaseEvent({data:{item:{id:t.options.formOptions.document.scheme}}}))}));var e=[{id:"2",title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_2"),icon:"landing-ui-crm-entity-type2"},{id:"3",title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_3"),icon:"landing-ui-crm-entity-type3"},{id:"4",title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_4"),icon:"landing-ui-crm-entity-type4"},{id:"310",title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_310"),icon:"landing-ui-crm-entity-type310"}];if(t.isDynamicAvailable()){e.push({id:"smart",title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_5"),icon:"landing-ui-crm-entity-type5"})}if(t.options.isLeadEnabled){e.unshift({id:"1",title:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_TYPE_1"),icon:"landing-ui-crm-entity-type1"})}return new a.RadioButtonField({selector:"scheme",value:function(){var e=d.Text.toNumber(t.options.formOptions.document.scheme);if(babelHelpers.classPrivateFieldGet(t,E).isDefaultScheme(e)&&babelHelpers.classPrivateFieldGet(t,E).isInvoice(e)){return babelHelpers.classPrivateFieldGet(t,E).getSpecularSchemeId(e)}if(String(t.options.formOptions.document.scheme)==="310"){return 310}var i=t.getSchemeById(t.options.formOptions.document.scheme);if(d.Type.isPlainObject(i)&&i.dynamic===true){return"smart"}return String(e)}(),items:e,onChange:t.onTypeChange.bind(t)})}))}},{key:"getDealCategoryField",value:function e(){var t=this;return this.cache.remember("dealCategoryField",(function(){return new p({categories:t.options.categories,value:{category:t.options.formOptions.document.deal.category}})}))}},{key:"getDynamicCategoriesField",value:function e(t){var i=this;return this.cache.remember("dynamicCategories#".concat(t),(function(){var e=i.getDynamicSchemeById(t);return new p({listTitle:c.Loc.getMessage("LANDING_FORM_SETTINGS_SMART_STAGES_FIELD_TITLE"),categories:e.categories,value:{category:i.options.formOptions.document.dynamic.category}})}))}},{key:"getDuplicatesEnabledField",value:function e(){var t=this;return this.cache.remember("duplicatesEnabledField",(function(){return new BX.Landing.UI.Field.Checkbox({selector:"duplicatesEnabled",compact:true,value:[t.options.formOptions.document.deal.duplicatesEnabled||"Y"],items:[{name:c.Loc.getMessage("LANDING_FORM_SETTINGS_CRM_DUPLICATES_ENABLED"),value:true}]})}))}},{key:"getSchemeById",value:function e(t){var i=this;return this.options.dictionary.document.schemes.find((function(e){return String(e.id)===String(t)||t==="smart"&&e.dynamic&&String(e.id)===String(i.getSelectedSchemeId())}))}},{key:"getDynamicSchemeById",value:function e(t){var i=this.getSchemeById(t),n=i.mainEntity;return this.options.dictionary.document.dynamic.find((function(e){return String(e.id)===String(n)}))}},{key:"setLastScheme",value:function e(t){this.cache.set("lastScheme",t)}},{key:"getLastScheme",value:function e(){return this.cache.get("lastScheme")}},{key:"setLastDealCategory",value:function e(t){this.cache.set("lastDealCategory",t)}},{key:"getLastDealCategory",value:function e(){return this.cache.get("lastDealCategory",null)}},{key:"onTypeChange",value:function e(t){var i=t.getData(),n=i.item;var a=this.getSchemeById(n.id);this.clear();this.addItem(this.getHeader());this.addItem(this.getTypesField());if(this.isDynamicAvailable()){this.addItem(this.getDynamicEntitySettingsForm());this.getDynamicEntitySettingsForm().hide()}var r=this.getExpertSettingsForm();r.clear();if(String(n.id)==="1"||String(n.id)==="8"){r.addField(this.getType1Header());r.addField(this.getDuplicatesField())}if(String(n.id)==="2"||String(n.id)==="5"){r.addField(this.getType2Header());r.addField(this.getDuplicatesField())}if(String(n.id)==="3"||String(n.id)==="6"){r.addField(this.getType3Header());r.addField(this.getDealCategoryField());r.addField(this.getDuplicatesEnabledField());r.addField(this.getDuplicatesField())}if(String(n.id)==="4"||String(n.id)==="7"){r.addField(this.getType4Header());r.addField(this.getDuplicatesField())}if(String(n.id)==="310"){r.addField(this.getType6Header());r.addField(this.getDuplicatesField())}if(d.Text.toNumber(n.id)>4&&d.Type.isPlainObject(a)&&a.dynamic!==true&&String(n.id)!=="9"||this.getOrderSettingsForm().isOpened()){this.getOrderSettingsForm().onSwitchChange(true)}if(d.Type.isPlainObject(a)&&(String(n.id)==="smart"||a.dynamic===true)&&this.isDynamicAvailable()){r.addField(this.getDynamicHeader(a.name));var s=this.getDynamicSchemeById(a.id);if(s&&s.categories){r.addField(this.getDynamicCategoriesField(a.id))}r.addField(this.getDuplicatesField());if(String(a.id).endsWith("1")){this.getOrderSettingsForm().onSwitchChange(true)}this.getDynamicEntitySettingsForm().show()}this.addItem(r);if(String(n.id)!=="310"){this.addItem(this.getOrderSettingsForm())}}},{key:"setAdditionalValue",value:function e(t){this.cache.set("additionalValue",t)}},{key:"getAdditionalValue",value:function e(){return this.cache.get("additionalValue",{})}},{key:"getEntityChangeConfirm",value:function e(){return this.cache.remember("entityChangeConfirm",(function(){return new o.MessageBox({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_SCHEME_CHANGE_CONFIRM_TITLE"),buttons:o.MessageBoxButtons.OK_CANCEL})}))}},{key:"getDealCategoryChangeConfirm",value:function e(){return this.cache.remember("dealCategoryChangeConfirm",(function(){return new o.MessageBox({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_SCHEME_CHANGE_CONFIRM_TITLE"),buttons:o.MessageBoxButtons.OK_CANCEL})}))}},{key:"getCreateOrderChangeConfirm",value:function e(){return this.cache.remember("createOrderChangeConfirm",(function(){return new o.MessageBox({title:c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_SCHEME_CREATE_ORDER_CHANGE_CONFIRM_TITLE"),buttons:o.MessageBoxButtons.OK_CANCEL,message:c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_CREATE_ORDER_MESSAGE_BOX_TITLE_1")})}))}},{key:"onChange",value:function e(i){var n=this;var a=this.getValue();var s=this.getSchemeById(a.document.scheme);if(d.Type.isPlainObject(s)){var o=s.entities;var l=this.options.formOptions.presetFields.filter((function(e){return!o.includes(e.entityName)})).map((function(e){return n.getCrmFieldById("".concat(e.entityName,"_").concat(e.fieldName))}));if(d.Type.isArrayFilled(l)){var g=c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_ITEM_TEMPLATE");var u=d.Text.encode(g.replace("{text}",s.name));var m=function(){var e=l.map((function(e){return g.replace("{text}",d.Text.encode(e.caption))}));if(l.length>1){var t=e.pop();return c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_SCHEME_CHANGE_CONFIRM_TEXT").replace("{fieldsList}",e.join(", ")).replace("{lastField}",d.Text.encode(t)).replaceAll("{entityName}",u)}return c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_SCHEME_CHANGE_CONFIRM_TEXT_1").replace("{fieldName}",e.join(", ")).replaceAll("{entityName}",u)}();var h=this.getEntityChangeConfirm();h.setOkCallback((function(){h.close();h.getOkButton().setDisabled(false);h.getCancelButton().setDisabled(false);var e=n.options.formOptions.presetFields.filter((function(e){return o.includes(e.entityName)}));n.setLastScheme(s.id);n.setAdditionalValue({presetFields:e});n.options.formOptions.presetFields=e;n.emit("onChange",f(f({},i.getData()),{},{skipPrepare:true}));n.setAdditionalValue({})}));h.setCancelCallback((function(){h.close();h.getOkButton().setDisabled(false);h.getCancelButton().setDisabled(false);var e=n.getSchemeById(n.getLastScheme());if(e.dynamic){n.getTypesField().setValue("smart",true);n.getDynamicEntitiesField().setValue(e.mainEntity,true)}else{n.getTypesField().setValue(e.id)}n.onTypeChange(new r.BaseEvent({data:{item:{id:e.id}}}))}));h.setMessage(m);h.show();return}if(String(s.id)==="3"||String(s.id)==="6"){var p=this.getLastDealCategory();if(d.Text.toNumber(a.document.deal.category)!==d.Text.toNumber(p)){var y=this.options.formOptions.presetFields.find((function(e){return e.entityName==="DEAL"&&e.fieldName==="STAGE_ID"}));if(y){var _=this.getCrmFieldById("DEAL_STAGE_ID");var S=this.getDealCategoryChangeConfirm();var T=c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_ITEM_TEMPLATE").replace("{text}",d.Text.encode(_.caption));var C=c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_CATEGORY_CHANGE_CONFIRM_TEXT").replace("{fieldName}",T);S.setMessage(C);S.setOkCallback((function(){S.close();S.getOkButton().setDisabled(false);S.getCancelButton().setDisabled(false);var e=n.options.formOptions.presetFields.filter((function(e){return e!==y}));n.options.formOptions.presetFields=e;n.setLastDealCategory(a.document.deal.category);n.setAdditionalValue({presetFields:e});n.emit("onChange",f(f({},i.getData()),{},{skipPrepare:true}));n.setAdditionalValue({})}));S.setCancelCallback((function(){S.close();S.getOkButton().setDisabled(false);S.getCancelButton().setDisabled(false);n.getDealCategoryField().setValue({category:n.getLastDealCategory()});n.setAdditionalValue({})}));S.show();return}}}}if(!babelHelpers.classPrivateFieldGet(this,E).isInvoice(s.id)&&a.document.payment.use){var F=this.getCreateOrderChangeConfirm();F.setButtons([(new t.Button).setColor(t.ButtonColor.PRIMARY).setText(c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_CREATE_ORDER_MESSAGE_BOX_CANCEL")).setNoCaps(true).bindEvent("click",(function(e){F.close();e.setDisabled(false);var t=n.getOrderSettingsForm().getSwitch();t.setValue(true);t.onChange();n.onChange(i)})),(new t.Button).setColor(t.ButtonColor.LIGHT).setText(c.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_CRM_CREATE_ORDER_MESSAGE_BOX_OK")).setNoCaps(true).bindEvent("click",(function(e){F.close();e.setDisabled(false);n.options.formOptions.payment.use=false;n.onChange(i)}))]);F.show()}this.emit("onChange",f(f({},i.getData()),{},{skipPrepare:true}))}},{key:"getCrmFieldById",value:function e(t){return Object.values(this.options.crmFields).reduce((function(e,t){return[].concat(babelHelpers.toConsumableArray(e),babelHelpers.toConsumableArray(t.FIELDS))}),[]).find((function(e){return e.name===t}))}},{key:"getSelectedSchemeId",value:function e(){var t=this.getTypesField().getValue();if(String(t)==="smart"){var i=this.getDynamicEntitiesField().getValue();if(this.getOrderSettingsForm().isOpened()){return"".concat(i,"1")}return"".concat(i,"0")}return t}},{key:"valueReducer",value:function e(t){var i=this.getDuplicatesField().getValue()[0];var n={duplicateMode:i==="ALLOW"?"":i,scheme:this.getSelectedSchemeId(),deal:{duplicatesEnabled:d.Text.toBoolean(this.getDuplicatesEnabledField().getValue()[0])},payment:{use:this.options.formOptions.payment.use,payer:this.options.formOptions.payment.payer,disabledSystems:this.options.formOptions.payment.disabledSystems},dynamic:{category:null}};if(this.getOrderSettingsForm().isOpened()){if(String(n.scheme)==="1"){n.scheme="8"}if(String(n.scheme)==="2"){n.scheme="5"}if(String(n.scheme)==="3"){n.scheme="6"}if(String(n.scheme)==="4"){n.scheme="7"}}if(String(n.scheme)==="3"||String(n.scheme)==="6"){n.deal.category=this.getDealCategoryField().getValue().category}var a=this.getSchemeById(n.scheme);var r=this.getDynamicSchemeById(n.scheme);if(d.Type.isPlainObject(a)&&a.dynamic&&r&&r.categories){n.dynamic.category=this.getDynamicCategoriesField(a.id).getValue().category}return f({document:n},this.getAdditionalValue())}}]);return n}(n.ContentWrapper);e.default=T})(this.BX.Landing.Ui.Panel.Formsettingspanel.Content=this.BX.Landing.Ui.Panel.Formsettingspanel.Content||{},BX.UI,BX.Landing.UI.Card,BX.Landing.UI.Panel,BX.Landing.UI.Field,BX.Event,BX.Landing.UI.Form,BX.UI.Dialogs,BX.Landing.UI.Field,BX.Landing,BX,BX.Landing.Ui.Panel.Formsettingspanel.Content.Crm);
//# sourceMappingURL=crm.bundle.map.js